﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LunarSF.SHomeWorkshop.LunarMarkdownEditor.Utils
{
    /// <summary>
    /// Reveal.js 定义的幻灯片切换特效名称。
    /// </summary>
    class Transition
    {
        static Transition()
        {
            TransitionsList.Add(new Transition("none", "n", "无", "w", "Switch backgrounds instantly", "直接切换背景"));
            TransitionsList.Add(new Transition("fade", "f", "淡化", "dh", "Cross fade - default for background transitions", "淡化切换－背景切换的默认方式"));
            TransitionsList.Add(new Transition("slide", "s", "幻灯片", "hdp", "Slide between backgrounds - default for slide transitions", "在背景间切换－幻灯片切换默认方式"));
            TransitionsList.Add(new Transition("convex", "v", "凸镜", "tj", "Switch backgrounds instantly", "凸镜效果切换"));
            TransitionsList.Add(new Transition("concave", "c", "凹镜", "aj", "Slide at a concave angle", "凹镜效果切换"));
            TransitionsList.Add(new Transition("zoom", "z", "缩放", "sf", "Scale the incoming slide up so it grows in from the center of the screen", "缩放效果切换"));

            TransitionsList.Add(new Transition("none-in", "ni", "无入", "wr", "Switch backgrounds instantly", "直接切换背景"));
            TransitionsList.Add(new Transition("fade-in", "fi", "淡入", "dr", "Cross fade - default for background transitions", "淡化切换－背景切换的默认方式"));
            TransitionsList.Add(new Transition("slide-in", "si", "幻灯片入", "hdpr", "Slide between backgrounds - default for slide transitions", "在背景间切换－幻灯片切换默认方式"));
            TransitionsList.Add(new Transition("convex-in", "vi", "凸镜入", "tjr", "Switch backgrounds instantly", "凸镜效果切换"));
            TransitionsList.Add(new Transition("concave-in", "ci", "凹镜入", "ajr", "Slide at a concave angle", "凹镜效果切换"));
            TransitionsList.Add(new Transition("zoom-in", "zi", "缩放入", "sfr", "Scale the incoming slide up so it grows in from the center of the screen", "缩放效果切换"));

            TransitionsList.Add(new Transition("none-out", "no", "无出", "wc", "Switch backgrounds instantly", "直接切换背景"));
            TransitionsList.Add(new Transition("fade-out", "fo", "淡出", "dc", "Cross fade - default for background transitions", "淡化切换－背景切换的默认方式"));
            TransitionsList.Add(new Transition("slide-out", "so", "幻灯片出", "hdpc", "Slide between backgrounds - default for slide transitions", "在背景间切换－幻灯片切换默认方式"));
            TransitionsList.Add(new Transition("convex-out", "vo", "凸镜出", "tjc", "Switch backgrounds instantly", "凸镜效果切换"));
            TransitionsList.Add(new Transition("concave-out", "co", "凹镜出", "ajc", "Slide at a concave angle", "凹镜效果切换"));
            TransitionsList.Add(new Transition("zoom-out", "zo", "缩放出", "sfc", "Scale the incoming slide up so it grows in from the center of the screen", "缩放效果切换"));
        }

        /// <summary>
        /// 将别名转换为 reveal.js 定义的特效字符串。
        /// </summary>
        /// <param name="oneOfName"></param>
        /// <returns></returns>
        public static string GetTransitionName(string oneOfName)
        {
            if (oneOfName == null) return "";
            var alias = oneOfName.Trim(new char[] { ' ', '　', '\t', });

            foreach (var fali in TransitionsList)
            {
                var lower = oneOfName.ToLower().Replace("－", "").Replace("—", "");
                if (lower == fali.TransitionName) return fali.TransitionName;
                if (fali.Alias1 == lower || fali.Alias2 == lower || fali.Alias3 == lower || fali.TransitionName == lower) return fali.TransitionName;
            }

            return "[UnKnown]";
        }

        public static List<Transition> TransitionsList { get; } = new List<Transition>();

        public Transition(string name, string alias1, string alias2, string alias3, string note, string cnNote)
        {
            TransitionName = name;
            Alias1 = alias1;
            Alias2 = alias2;
            Alias3 = alias3;
            Note = note;
        }

        public string Alias1 { get; }
        public string Alias2 { get; }
        public string Alias3 { get; }
        public string TransitionName { get; }
        public string Note { get; }
    }
}
